import React, { Component } from 'react';
import {
  Image,StyleSheet,AppRegistry,Dimensions,AsyncStorage
} from 'react-native';

import { StackNavigator } from 'react-navigation';
import {NavigationActions} from 'react-navigation';
import pxToDp from './js/common/comm';
import MyApp from './js/page/Main';
import Notice from './js/page/Notice';
import * as DATA from './js/data/data';
import * as COMM from './js/common/comm';

var navi;

class Welcome extends Component {
  // 构造
    constructor(props) {
      super(props);
      let width = Dimensions.get('window').width;
      let height = Dimensions.get('window').height;
      // 初始状态
      this.state = {
        width:width,
        hegiht:height
      };
        //清除登录状态
        COMM.removeKey('loginkey');
    }
  render() {
    navi = this.props.navigation.navigate;
    setTimeout(() => {
      //不返回欢迎页面
      const resetActions = NavigationActions.reset({
            index: 0,
            actions: [NavigationActions.navigate({routeName: 'Main'})]
        });
      this.props.navigation.dispatch(resetActions);
    }, 1000);
    return (
        <Image
            resizeMode='contain'
            style={{width:this.state.width,height:this.state.hegiht}}
            source={{uri:DATA.WELCOME_IMG}}>
        </Image>
    );
  }
}

const styles = StyleSheet.create({
  img: {
    flex:1,
    alignItems:'center',
    justifyContent:'center',
    width:null,
    height:null,
    //不加这句，就是按照屏幕高度自适应
    //加上这几，就是按照屏幕自适应
    //resizeMode:Image.resizeMode.contain,
    //祛除内部元素的白色背景
    backgroundColor:'rgba(0,0,0,0)'
  }
});

const fumengapp = StackNavigator({
  Welcome: {
    screen: Welcome,
    navigationOptions : {
        header: null
    }
  },
  Main: {
    screen: MyApp,
    navigationOptions : {
      header: null
    }
  },
  Notice: {
    screen:Notice
  }
});

AppRegistry.registerComponent('fumengapp', () => fumengapp);
